{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"contentcontainer med left\" style=\"margin-left: -50px;\">\n",
    "    <dl class=\"dl-horizontal\">\n",
    "      <dt>Title</dt> <dd> Linked pointer cross-section example</dd>\n",
    "      <dt>Description</dt> <dd>A linked streams example demonstrating how to use PointerXY stream linked across two plots.</dd>\n",
    "      <dt>Backends</dt> <dd> Bokeh</dd>\n",
    "      <dt>Tags</dt> <dd> streams, linked, position, interactive</dd>\n",
    "    </dl>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import holoviews as hv\n",
    "from holoviews import streams\n",
    "hv.extension('bokeh')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%opts Curve [width=100]\n",
    "\n",
    "# Create two images\n",
    "x,y = np.meshgrid(np.linspace(-5,5,101), np.linspace(5,-5,101))\n",
    "img1 = hv.Image(np.sin(x**2+y**2))\n",
    "img2 = hv.Image(np.sin(x**2+y**3))\n",
    "\n",
    "# Declare PointerX and dynamic VLine\n",
    "posx = hv.streams.PointerX()\n",
    "vline = hv.DynamicMap(lambda x: hv.VLine(x or -100), streams=[posx])\n",
    "\n",
    "# Declare cross-sections at PointerX location\n",
    "crosssection1 = hv.DynamicMap(lambda x: img1.sample(x=x if x else 0), streams=[posx])\n",
    "crosssection2 = hv.DynamicMap(lambda x: img2.sample(x=x if x else 0), streams=[posx])\n",
    "\n",
    "# Combine images, vline and cross-sections\n",
    "((img1 * vline) << crosssection1) + ((img2 * vline) << crosssection2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center><img src=\"http://assets.holoviews.org/gifs/examples/streams/bokeh/linked_pointer_crosssection.gif\" width=600></center>"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
